package com.horqian.api.oktoberfest

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.os.Bundle
import android.util.Log
import android.widget.ImageView
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.GridLayoutManager
import com.horqian.api.oktoberfest.databinding.TipDialogBinding
import com.lxj.xpopup.core.BasePopupView
import com.lxj.xpopup.core.CenterPopupView
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

/**
 * @author 付佳豪
 * @date 2023/7/5 20:03
 * @desc
 */
class TipDialog(context: Context) :
    Dialog(context,R.style.dialog_bg_style) {
    private val mBinding by lazy {
        TipDialogBinding.inflate(layoutInflater)
    }


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContentView(mBinding.root)

        val width = context.resources.displayMetrics.widthPixels
        val height = context.resources.displayMetrics.heightPixels
        window?.setLayout(
            (width * 0.625).toInt(),
            (height * 0.375).toInt()
        )



    }

     fun showTip(isSuccess: Boolean, msg: String = "") {
        if (isSuccess) {
            mBinding.ivState.setImageResource(R.drawable.baseline_check_circle_24)
            mBinding.tvMsg.text = "扫码成功"
            mBinding.tvMsg.setTextColor(Color.BLACK)
        } else {
            mBinding.ivState.setImageResource(R.drawable.baseline_cancel_24)
            mBinding.tvMsg.text = msg
            mBinding.tvMsg.setTextColor(Color.RED)
        }
        if (!isShowing){
            show()
        }
    }
}